package functions

import (
	"github.com/shopspring/decimal"
)

func LT_any_int(val interface{}, num int) bool {
	var d decimal.Decimal
	switch v := val.(type) {
	case int:
		return v < num
	case int64:
		return v < int64(num)
	case int32:
		return int(v) < num
	case float64:
		d = decimal.NewFromFloat(v)
	case float32:
		d = decimal.NewFromFloat32(v)
	case string:
		fd, err := decimal.NewFromString(v)
		if err != nil {
			throwException("Less than error: %s, near ", err)
		}
		d = fd
	case decimal.Decimal:
		d = v
	default:
		throwException("Less than error: mismatched types %T and %T, near ", val, num)
	}
	return LT_decimal_decimal(d, decimal.NewFromInt(int64(num)))
}

func LT_any_float(val interface{}, num float64) bool {
	var d decimal.Decimal
	switch v := val.(type) {
	case int:
		d = decimal.NewFromInt(int64(v))
	case int64:
		d = decimal.NewFromInt(v)
	case int32:
		d = decimal.NewFromInt32(v)
	case float64:
		return v < num
	case float32:
		return float64(v) < num
	case string:
		fd, err := decimal.NewFromString(v)
		if err != nil {
			throwException("Less than error: %s, near ", err)
		}
		d = fd
	case decimal.Decimal:
		d = v
	default:
		throwException("Less than error: mismatched types %T and %T, near ", val, num)
	}
	return LT_decimal_decimal(d, decimal.NewFromFloat(num))
}

func LT_decimal_decimal(v1, v2 decimal.Decimal) bool {
	return v1.LessThan(v2)
}
